$(function() {
	admin.homemakingType.init();
});
Namespace('admin.homemakingType', {
	init : function() {
		easyui.util.initDatagrid('#datagrid', {
			onDblClickRow : function() {
				var row = $('#datagrid').datagrid('getSelected');
				admin.homemakingType.edit(row.id);
			}
		});
	},
	query : function() {
		if (!$('#query-form').form('validate'))
			return;
		var data = $('#query-form').form('jsonObject');
		$('#datagrid').datagrid('load', data);
	},
	edit:function(id) {
		if(id==null) {
			top.showInfo('请选择需要修改的记录!');
			return;
		}
		getDialog('data-dialog').dialog({
			href:contextPath+'/homemaking/type/edit/'+id,
			title: '修改类别',
		    width: 500,
		    height: 450,
		    buttons:[{
				text:'确定',
				iconCls:'icon-ok',
				handler:function() {
					admin.homemakingType.doEdit();
				}
			},{
				text:'取消',
				iconCls:'icon-cancel',
				handler:function(){
					$('#data-dialog').dialog('close');
				}
			}]
		});
	},
	doEdit:function() {
		if(!$('#data-form').form('validate')) return;
		var data=$('#data-form').form('jsonObject');
		var img = "";
		var imglist = $(".img_imglist img");
		if (imglist && imglist.length > 0) {
			imglist.each(function(){
			    if (img == "") {
			    	img += $(this).attr("src").replace(imgFilePath,"");
			    } else {
			    	img += ";" + $(this).attr("src").replace(imgFilePath,"");
			    }
			});
		}
		data.img = img;
		$('#data-dialog').dialog('close');
		
		$('#datagrid').datagrid('loading');
		var row = $('#datagrid').datagrid('getSelected');
		$.post(contextPath+'/homemaking/type/edit',data,function(result) {
			$('#datagrid').datagrid('loaded');
			if(result.code==1) {
				top.showInfo('修改成功!');
				$('#datagrid').datagrid('reload');
			} else {
				if (result.msg) {
					top.showInfo(result.msg);
				} else {
					top.showInfo('修改失败!');
				}
			}
		});
	},
	editDict:function(id) {
		if (id != null) {
			top.addTab(id,'服务介绍', contextPath+'/homemaking/sys/dict/listDictType/' + id);
		}
	},
	addImg:function(id){
		getDialog('query-dialog').dialog({
			href:contextPath+'/homemaking/sys/dict/imgUpload/type',
			title: '选择文件',
		    width: 350,
		    height: 250,
		    buttons:[{
				text:'上传',
				handler:function(){
					uploaderStart(id);
				}
			}]
		});
		
	}
});